package com.wkk.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.wkk.rabbitmq.Sender;

@Controller
@RequestMapping("mq")
@CrossOrigin // 跨域允许
public class RabbitMqController {
	@Resource
	private Sender sender;

	@ResponseBody
	@RequestMapping("mq")
	public String mq() {
		sender.send();
		return null;

	}

	/*
	 * private final static String QUEUE_NAME = "hello";
	 * 
	 * public static void main(String[] argv) throws Exception {
	 * 
	 * ConnectionFactory factory = new ConnectionFactory();
	 * factory.setHost("60.205.228.65"); factory.setUsername("wkk");
	 * factory.setPassword("8864515"); factory.setPort(5672); Connection connection
	 * = factory.newConnection(); Channel channel = connection.createChannel();
	 * channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message =
	 * "Hello World!"; channel.basicPublish("", QUEUE_NAME, null,
	 * message.getBytes()); System.out.println(" [x] Sent '" + message + "'");
	 * channel.close(); connection.close(); }
	 */
}
